//MyAccount Form validations
//var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var members="";
function myAccountForm(){
    var charactervalidation = /^[a-zA-Z\s]*$/;
	var flag=true;
	var userName=$('#inputUser').val();
	var email=$('#inputEmail').val();
	var phone=$('#inputPh').val();
	var Alterphone=$('#alterphone').val();
	var address=$('#txtArea').val();
	var location=$('#location').val();
	var pincode=$('#pincode').val();
	var hid=$('#hid').val();
	if(userName==""){
		$('#userNameError').html(Account_page_user_name);
		flag=false;
	}else if(!userName.match(charactervalidation)){
	    $('#userNameError').html(Account_page_charactervalidation);
		flag=false;
	}else{
		$('#userNameError').html('');
	}
	
	if(email==""){
	   $("#emailError").html(Account_page_email);
	   flag=false;   
	}else{
	    if(validateEmail(email)==0){
		  $("#emailError").html(Account_page_erroremail);
		  flag=false; 
	    }else{
			  $("#emailError").html(""); 
			}
	} 
	if(phone==""){
		$('#phoneNumberError').html(Account_page_phonenumber);
		flag=false;
	}else if(isNaN(phone)){
		  $('#phoneNumberError').html(Account_page_numbervalidation);
		  flag=false;
	}else{
		$('#phoneNumberError').html('');
	}
	
	if(Alterphone==""){
	   $("#erroralterphone").html(Account_page_alterphonenumber);
	   flag=false;   
	}else if(isNaN(Alterphone)){
	   $("#erroralterphone").html(Account_page_numbervalidation);
	   flag=false;   
	}else{
	  $("#erroralterphone").html("");
	}
	
	if(location==""){
		$('#errorLocation').html(Account_page_location );
		flag=false;
	}else{
		$('#errorLocation').html('');
	}
	
	if(address==""){
		$('#addressError').html(Account_page_address);
		flag=false;
	}else{
		$('#addressError').html('');
	}
	
	if(pincode==""){
		$('#errorPincode').html(Account_page_pincode);
		flag=false;
	}else if(isNaN(pincode)){
	   $("#errorPincode").html(Register_page_numbervalidation);
	   flag=false;
	}else{
		$('#errorPincode').html('');
	}
	if(flag==true){
		$('#accountReload').html('<img src="images/ajax-loader.gif"/>');
		$.ajax({
			type		:	'PUT',
			url			:  	webServiceUrl+'registration/'+hid,
			dataType	: 	"json",
			data		:	$('#accountForm1').serialize(),
			success: function(data){
				$('#accountReload').html('');
				if(data.value==1){
					$('updatePhone').html('Ph:&nbsp;'+phone);
					$('updateLocation').html(location);
					sessionStorage.setItem( 'shop_phone', JSON.stringify(phone) );
					sessionStorage.setItem( 'shop_location', JSON.stringify(location) );
					$('#success_alert').show();
					$('#sucessDiv').html(Account_page_success_message);
					$("html, body").animate({ scrollTop: 0 }, 600);
					$('#success_alert').delay(3000).fadeOut('slow');
				}else{
					$('#sucessDiv').html('');
				}
			}
			
		});
	}
}
//login Form validations
function loginForm(){
	var flag=true;
	var userName=$('#username').val();
	var password=$('#password').val();
	if(userName==""){
	   $("#usernameError").html(Login_user_email);
	   flag=false;   
	}else{
	    if(validateEmail(userName)==0){
		  $("#usernameError").html(Login_user_erroremail);
		  flag=false; 
	    }else{
			  $("#usernameError").html(""); 
		}
	}
	
	if(password==""){
		$('#pwdError').html(Login_user_password);
		flag=false;
	}else{
		$('#pwdError').html('');
	}
	
	if(flag==false){
		return false;
	}else{
	$('#reload').html('<img src="images/ajax-loader.gif"/>');
		$.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'login',
			dataType	: 	"json",
			data		:	{
								email:userName,pwd:password,user_type_id:'3'
							},
			success: function(data){
				$('#reload').html('');
				 if(data.status=="success"){
					var obj = eval("(" + data.UserDetails + ")");
					$.each(obj, function (index,Object) {
						var user_id		=	Object.user_id;
						var email		=	Object.email;
						var phone		=	Object.phone;
						var location	=	Object.location;
						var shop_name	=	Object.user_name;
						sessionStorage.setItem( 'shop_user_id', JSON.stringify(user_id) );		
						sessionStorage.setItem( 'shop_email', JSON.stringify(email) );
						sessionStorage.setItem( 'shop_phone', JSON.stringify(phone) );
						sessionStorage.setItem( 'shop_location', JSON.stringify(location) );
						sessionStorage.setItem( 'shop_name', JSON.stringify(shop_name) );
					});
					window.location="account.html";
				}else{
					$('#logsucess').html(Login_error_message);
				}
			}
		});
	}
}
//Forget Password Form validations
function forgetForm(){
    var flag=true;
	var email=$('#inputuser').val();
	
	if(email==""){
	   $("#forgetMailError").html(Forgotpassword_email);
	   flag=false;   
	}else{
	    if(validateEmail(email)==0){
		  $("#forgetMailError").html(Forgotpassword_error_email);
		  flag=false; 
	    }else{
			  $("#forgetMailError").html(""); 
			}
	}
	
	if(flag==false){
		return false;
	}else{
		   $('#forgetReload').html('<img src="images/ajax-loader.gif"/>');
	       $.ajax({
				type		:	'POST',
				url			:  	webServiceUrl+'forgetpassword',
				dataType	: 	"json",
				data		:	{
									email:email,type:3
								},
				success: function(data){
				$('#forgetReload').html('');
					if(data.value==1){
						$('#successfpassword').html(Forgotpassword_success_message);
					}else{
						$('#successfpassword').html(Forgotpassword_error_message);
					}
				}
			});
	       
	
	}
}

//Email validation server side
function emailValidation(){
	var emailcheck=$('#inputEmail').val();
	if(emailcheck!==''){
		if(validateEmail(emailcheck)=='0')
		{
			$('#errorEmail').html(sever_error_email);		
		}else{	
			$.ajax({
				type		:	'GET',
				url			:  	webServiceUrl+'login/'+emailcheck,
				dataType	: 	"json",
				success: function(data){
					if(data.value==1){
						$('#hidemailerror').val('1');
						$('#errorEmail').html(server_check_email);
						return 1;
					}else{
						$('#hidemailerror').val('0');
						$('#errorEmail').html("");
						return 0;
					}
				}
			});
		}
  }
}

// Change Password
function changePassword(){
   var flag=true;
   var Oldpassword=$("#oldpassword").val();
   var Newpassword=$("#newPassword").val();
   var Confirmpassword=$("#Confirmpassword").val();
	if(Oldpassword==""){
      $("#errorOldpassword").html(Change_old_password);
	  flag=false;
	}else{
      $("#errorOldpassword").html("");
	}
	
	if(Newpassword==""){
      $("#errorNewpassword").html(Change_new_password);
	  flag=false;
	}else{
      $("#errorNewpassword").html("");
	}
	
	if(Confirmpassword==""){
        $("#errorConfirmpassword").html(Change_confirm_password);
		flag=false;
	}else if(Newpassword!=Confirmpassword){
	   $("#errorConfirmpassword").html(Change_errorconfirm_password);
	   flag=false;
	}else{
       $("#errorConfirmpassword").html("");
	}
	
	if(flag==true){
		$('#changePasswordReload').html('<img src="images/ajax-loader.gif"/>');
		var user_id = JSON.parse(sessionStorage["shop_user_id"]);
        $.ajax({
				type		:	'PUT',
				url			:  	webServiceUrl+'changepassword/'+user_id,
				dataType	: 	"json",
				data        : {old_password:Oldpassword,cnf_password:Confirmpassword},
				success: function(data){
					$('#changePasswordReload').html('');
					if(data.value==1){
						$('#success_alert').show();
						$('#errorCpassword').html(Change_successpassword_message);
						$("html, body").animate({ scrollTop: 0 }, 600);
						$('#success_alert').delay(3000).fadeOut('slow');
						$('#error_alert').hide();
						$("#oldpassword").val('');
					    $("#newPassword").val('');
						$("#Confirmpassword").val('');
					}else{
						$('#error_alert').show();
						$('#errorCpasswordError').html(Changepassword_error_message);
						$("html, body").animate({ scrollTop: 0 }, 600);
						//$('#error_alert').delay(3000).fadeOut('slow');
					}
				}
		});
	}
}

//Reset password
function passwordReset(){
  var flag=true;
  var Resetpassword=$("#resetPassword").val();
  var Confirmpassword=$("#Confirmpassword").val();
    if(Resetpassword==""){
      $("#errorResetpassword").html(Reset_newpassword);
	  flag=false;
	}else{
      $("#errorResetpassword").html("");
	}
	
	if(Confirmpassword==""){
        $("#errorConfirmpassword").html(Reset_confirm_password);
		flag=false;
	}else if(Resetpassword!=Confirmpassword){
	   $("#errorConfirmpassword").html(Resetpassword_confirm_errormessage);
	   flag=false;
	}else{
       $("#errorConfirmpassword").html("");
	}
	
	if(flag==false){
	   return false;
	}else{
	   var path = window.location.href;
	   path = path.replace(/\/$/, "");
	   path = decodeURIComponent(path);
       var id=path.split('=');
       var token=id[1];
	   $('#resetPasswordReload').html('<img src="images/ajax-loader.gif"/>');
	    $.ajax({
				type		:	'PUT',
				url			:  	webServiceUrl+'forgetpassword/'+token,
				dataType	: 	"json",
				data        : {cnf_password:Confirmpassword},
				success: function(data){
					$('#resetPasswordReload').html('');
					if(data.value==1){
						$('#success_alert').show();
						$('#errorSuccess').html(Resetpassword_success_message);
						$("html, body").animate({ scrollTop: 0 }, 600);
						$('#success_alert').delay(3000).fadeOut('slow');
						$('#error_alert').hide();
					}else{
						$('#errorSuccessError').html(Resetpassword_error_message);
					}
				}
		});
	}
}
function logoutFunction(){
	sessionStorage.removeItem("shop_user_id");
	sessionStorage.removeItem("shop_email");
	window.location="index.html";
}
function viewallDiscounts(){
	var user_id = JSON.parse(sessionStorage["shop_user_id"]);
	var count=0;
	var dhtml="";
	var address="";
	var prescription="";
	$.ajax({
		type		:	'GET',
		url			:  	webServiceUrl+'discounts',
		dataType	: 	"json",
		success: function(data){
			if(data.value==1){
				dhtml+='<table class="table table-bordered">'+
							'<tr class="table_th_bg">'+
							'<th>Post Order Date</th>'+
							'<th>Delivered Date</th>'+
							'<th>Shop Name</th>'+
							'<th>Shop Address</th>'+
							'<th>Prescription</th>'+
							'<th>Price</th>'+
							'<th>Discount</th>'+
						'</tr>';
				var obj = eval("(" + data.data + ")");
				$.each(obj, function (index,Object) {
					count++;
					address+='<p>'+Object.address+'</p>'+'<p>Location:'+Object.location+'</p>'+
					'<p>Pincode:'+Object.pincode+'</p>'+'<p>Contact:'+Object.phone+'</p>';
					var pdetails=Object.prescription_details;
					var details=pdetails.split('**');
					for(var i=0;i<=(details.length-1);i++){
						var names=details[i].split('$$');
						prescription+='<p>Tablet Name:'+names[0]+'&nbsp;&nbsp;&nbsp;Quantity:'+names[1]+'</p>';
					}
					dhtml+=	'<tr>'+
							'<td>'+Object.added_date+'</td>'+
							'<td>'+Object.delivered_date+'</td>'+
							'<td>'+Object.shop_name+'</td>'+
							'<td>'+address+'</td>'+
							'<td>'+prescription+'</td>'+
							'<td>Rs '+Object.price+'.00</td>'+
							'<td>Rs '+Object.discount+'.00</td>'+
						'</tr>';
					address="";
					prescription="";
				});
				dhtml+='</table>';
				$('.container_form_top').html(dhtml);
			}else{
				$('.container_form_top').html(Discounts_empty_message);
			}
		}
	});
}

//Customer Review list
function getAllReviewsFun(){
  var user_id = JSON.parse(sessionStorage["shop_user_id"]);
  $.ajax({
			type		:	'GET',
			url			:  	webServiceUrl+'reviews-and-ratings',
			dataType	: 	"json",
			success: function(data){
				if(data.value==1){
					var html="";
					var rhtml="";
					var obj = eval("(" + data.reviewslist + ")");
					$.each(obj, function (index,Object){
						html+='<div class="media">';
						html+='<a class="pull-left" href="#">';
						html+='<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile"></a>';		  
						html+='<div class="media-body">';
						var value=Object.rating;
						for(var i=1;i<=value;i++){
							rhtml+='<img class="star" src="images/green-star.png">';
						}for(var j=i;j<=5;j++){
							rhtml+='<img class="star" src="images/gray-star.png">';
						}
						html+='<h4>'+rhtml+'</h4>';
						html+='<h4 class="media-heading">'+Object.user_name+' To '+Object.shop_name+ ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tracking ID: '+Object.tracking_id+'</h4>';
						html+= Object.review;	 
						html+='</div>'; 
						html+='</div>';
						rhtml="";
					});
					$("#all_review_list").html(html);
				}else{
					$("#all_review_list").html(Review_list_empty_message);
				}
            }				
		});
}
//Shop  reply to complaints 
function validShopComplaint(){
    var flag=true;
	var complaintTrackId=$("#complaintId").val();
	var userComplaint=$("#textArea").val();
	
	if(complaintTrackId==""){
	   $("#errorComplaintTrackId").html(Complaint_track_id);
	   flag=false;   
	}else if(isNaN(complaintTrackId)){
	   $("#errorComplaintTrackId").html(Complaint_track_id_number);
	   flag=false;   
	}else{
	  $("#errorComplaintTrackId").html("");
	}
	
	if(userComplaint==""){
		$("#complaintError").html(Complaint);
		flag=false;
	}else{
		$("#complaintError").html("");
	}
	if(flag==false){
	   return false;
	}else{
	    $('#userComplaintReload').html('<img src="images/ajax-loader.gif"/>');
	    var user_id = JSON.parse(sessionStorage["shop_user_id"]);
		$.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'complaints',
			dataType	: 	"json",
			data		:	{user_id:user_id,complaint:userComplaint,tracking_id:complaintTrackId},
			success: function(data){
				$('#userComplaintReload').html('');
				if(data.value==1){
				        $("#complaintId").val("");
	                    $("#textArea").val("");
						$('#success_alert').show();
						$("#CheckComplaint").html(Complaint_success_message);
						$("html, body").animate({ scrollTop: 0 }, 600);
						$('#success_alert').delay(3000).fadeOut('slow');
				}else{
						$('#error_alert').show();
						$("#CheckComplaintError").html(Complaint_validtracking_message);
						$("html, body").animate({ scrollTop: 0 }, 600);
				}
			}
		});
	
	}
}
//All Complaints list

function getAllComplaintsFun(){
  $.ajax({
		type		:	'GET',
		url			:  	webServiceUrl+'all-complaints',
		dataType	: 	"json",
		success: function(data){
			if(data.value==1){
				var chtml='';
				var obj = eval("(" + data.complaints + ")");
				$.each(obj, function(index ,Object) {
							chtml+='<div class="media">'+
									'<a class="pull-left" href="#">'+
										'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
									'</a>'+
									'<div class="media-body">'+
										'<h4 id="shop_name_complaint" class="media-heading">'+Object.user_name+'&nbsp;&nbsp;&nbsp;&nbsp;'+'TRACKING ID:'+Object.complaint_on_id+'</h4>'+
										'<p id="shop_name_complaint_text">'+Object.complaint+'</p>';
					
						if(Object.reply_text!=null){
							chtml+='<div class="media">'+
								'<a class="pull-left" href="#">'+
								'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
								'</a>'+
								'<div class="media-body">'+
									'<h4 class="media-heading">Replay&nbsp;&nbsp;&nbsp;'+Object.shop_name+'</h4>'+
									'<p>'+Object.reply_text+'</p>';
								chtml+='</div>'+
							'</div>';
						}
					chtml+='</div>'+'</div>';
				});
				$("#complaint_replies").html(chtml);
			}else{
				$("#complaint_replies").html(Complaint_error_message);
			}
		}
		
	});
}
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//Order history

//orderConfirm
function orderConfirm(tracking_id){
var shop_id = JSON.parse(sessionStorage["shop_user_id"]);
	$.ajax({
			type		:	'PUT',
			url			:  	 webServiceUrl+'shop-discount-refunds/'+tracking_id+'-'+shop_id,
			dataType	: 	"json",
			data		:	{tracking_id:tracking_id,compliantType:"OrderConfirmed",complaint_id:"0"},
			success: function(data){
				if(data.value==1){
					$("#updatededeliverddate"+tracking_id).html(JSON.parse(data.delivered_date));
					$("#status"+tracking_id).html('Processed');
					$("#CompleteOrderconfirm"+tracking_id).html('');
				}
			}
		});
}
//send price to quotation 
function sendPriceToQuotationPopUp(order_delivery_details_id,tracking_id){
	var htmlPopup="";
	htmlPopup+='<div id="price'+order_delivery_details_id+'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><h3 id="myModalLabel">Send Price</h3></div><div id="popup" class="modal-body">';
			htmlPopup+='<form id="discounttForm"><p>Tracking Id:'+tracking_id+'</p>';
			htmlPopup+='<p>Price:<input type="text" id="pricevalue" name="pricevalue"/></p>'+
			'<p><input type="button" id="buttonPrice" name="buttonPrice" value="Send" onclick="sendPriceToOrder('+order_delivery_details_id+','+tracking_id+')"/><span id="errorpricevalue" name="errorpricevalue"></span></p>';
			htmlPopup+='</form>'+
				'<span id="sendsuccess" style="color:green"></span>';
			htmlPopup+='</div><div class="modal-footer"><button class="btn" data-dismiss="modal" ria-hidden="true">Close</button></div></div>';
			$('#send_quotation_price').html(htmlPopup);
			$('#price'+order_delivery_details_id).modal('show');
}
function sendPriceToOrder(order_delivery_details_id,tracking_id){
	var shop_id = JSON.parse(sessionStorage["shop_user_id"]);
	var price=$('#pricevalue').val();
	if(price==""){
		$('#errorpricevalue').html(Quotation_price);
	}else{
		$.ajax({
			type		:	'PUT',
			url			:  	webServiceUrl+'shop-orders/'+order_delivery_details_id,
			dataType	: 	"json",
			data		:	{price:price,t_id:tracking_id,complaintType:"sendPrice",shop_id:shop_id,user_id:"0",admin_id:"0",},
			success: function(data){
				if(data.value==1){
					$('#sendsuccess').html('Sended');
					$('#sendPrice'+order_delivery_details_id).html('Sended'+'/'+'<a href="#'+tracking_id+'" role="button" class="" data-toggle="modal">View</a>');
					$('#status'+order_delivery_details_id).html('Sent Price');
				}
			}
		});
	}
}

// Shop Complaints


function submitReplay(shop_id,complaint_id,complaint_on_id){
	var chtml="";
	var complaint_relpier_id = JSON.parse(sessionStorage["shop_user_id"]);
	var user_name = JSON.parse(sessionStorage["shop_name"]);
	var reply_text=$('#replaytext'+shop_id).val();
	if(reply_text!=""){
		$.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'renuwalorder',
			dataType	: 	"json",
			data		:	{complaint_id:complaint_id,complaint_relpier_id:complaint_relpier_id,reply_text:reply_text,tracking_id:complaint_on_id,user_id:'0',compliantType:"Complaint",shopId:shop_id},
			success: function(data){
				chtml+='<div class="media">'+
				'<a class="pull-left" href="#">'+
				'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
				'</a>'+
				'<div class="media-body">'+
					'<h4 class="media-heading">Replay TRACKING ID:'+complaint_on_id+'</h4>'+
					'<p>'+reply_text+'</p>'+
				'</div>'+
				'</div>';
				$('#appendDivs'+shop_id).append(chtml);
				$('#replayP'+complaint_id).remove();
				$('#replay_comment'+complaint_id).remove();
			}
		});
	}else{
		$('#errortext'+shop_id).html('Enter comment');
	}
	
}
//Shop reviews 

function pageselectCallbackShopOrder(page_index, jq){
	var items_per_page = $('#items_per_page').val();
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var pagei=page_index*items_per_page;
	var count=0;var html="";var phtml="";
	var auto_renewal='';
	var each_days='';
	var status='';
	var delivered_date='';
	var action='';				
	var viewDetailes='';				
	var immidiate='';				
	var deliverdDate='';				
	var viewAll="";
	var imagees="";
	var images="";
	var viewallImages="";
	var price="";
	var discount="";
	html+='<table class="table table-bordered">'+
				'<tr class="table_th_bg">'+
				'<th>Send Date</th>'+
				'<th>Prescription</th>'+
				'<th>Attachment</th>'+
				'<th>Status</th>'+
				'<th>Action</th>'+
			'</tr>';
	var obj = eval(members);
	$.each(obj, function (index,Object){
	if(pagei==index){
		if(pagei<max_elem){
			if(Object.prescription_upload_path!=""){
				var imagess=Object.prescription_upload_path;
				images=imagess.split('**');
				if(images.length>0){
				  for(var i=0;i<1;i++){
					   if(images[i]!=null){
							imagees+='<p><img src="'+uploadImgUrl+images[i]+'" width="100px" height="100px"/></p>';
							if(images.length>1){
								imagees+='<a href="#image'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">ViewAll</a>'
							}
						}else{
							imagees+='<p><img src="'+uploadImgUrl+'default.jpg" width="100px" height="100px"/></p>';
						}
					}
				}
			}else{
				imagees+='<p><img src="'+uploadImgUrl+'default.jpg" width="100px" height="100px"/></p>';
			}
			var pdetails=Object.prescription_details;
			var details=pdetails.split('**');
			  // alert(details[0]);return false;
			if(details.length>0){
			  for(var i=0;i<=1;i++){
				   //alert(details[i]);
				   if(typeof details[i]!='undefined'){
					var names=details[i].split('$$');
					phtml+='Tabletname:'+names[0]+'<br/> Quantity:'+names[1]+'<br/>';
					}
				}
				if(details.length>2){
				  phtml+='<a href="#viewall'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">ViewAll</a>';
				}
			}
			if(Object.auto_renewal==0 || Object.auto_renewal==null){
				auto_renewal='No';
			}else{
				auto_renewal='Yes';
			}
			if(Object.each_days==0 || Object.auto_renewal==null){
				each_days='No';
			}else{
				each_days=Object.each_days;
			}
			if(Object.status==1){
				if(Object.shop_order_status==0){
					status='Pending';
					action='<p id="sendPrice'+Object.order_delivery_details_id+'"><a href="javascript:void(0)" onclick="sendPriceToQuotationPopUp('+Object.order_delivery_details_id+','+Object.user_medicine_order_id+')">Send Price</a>'+'/'+'<a href="#'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">View</a></p>';
				}else if(Object.shop_order_status==1){
					status='Sent Price';
					action='<a href="#'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">View</a>';
				}else if(Object.shop_order_status==2){
					status='Confirm Order';
					action='<p><a href="#'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">View</a></p><p id="CompleteOrderconfirm'+Object.user_medicine_order_id+'"><a href="javascript:void(0)" onclick="orderConfirm('+Object.user_medicine_order_id+')">Complete Order</a></p>';
				}
			}else if(Object.status==2){
				status='Processed';
				action='<a href="#'+Object.user_medicine_order_id+'" role="button" class="" data-toggle="modal">View</a>';
			}
			if(Object.delivered_date=="" || Object.delivered_date==null){
				delivered_date="Not delivered";
			}else{
				delivered_date=Object.delivered_date;
			}
			if(Object.immediate==0 || Object.immediate==null){
				immidiate='Not Immidiate';
			}else{
				immidiate='Yes';
			}
			if(Object.delivered_date==null){
				var deliverdDate="Not Delivered ";
			}else{
				deliverdDate=Object.delivered_date;
			}
			count++;
			if(Object.price==null){
				price="No Price";
			}else{
				price=Object.price;
			}
			if(Object.discount==""){
				discount="No Discount";
			}else{
				discount=Object.discount;
			}
			viewDetailes+='<div id="'+Object.user_medicine_order_id+'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><h3 id="myModalLabel">Order Detailes</h3></div><div id="popup" class="modal-body">'+
					'<table class="table table-condensed">'+
						'<tr><th>Tracking_id</th><th>'+Object.user_medicine_order_id+'</th></tr>'+
						'<tr><th>Price</th><th>'+Object.price+'</th></tr>'+
						'<tr><th>Discount</th><th>'+Object.discount+'</th></tr>'+
						'<tr><th>Auto Renewal </th><th>'+auto_renewal+'</th></tr>'+
						'<tr><th>Days</th><th>'+each_days+'</th></tr>'+
						'<tr><th>Delivered Date</th><th id="updatededeliverddate'+Object.user_medicine_order_id+'">'+deliverdDate+'</th></tr>'+
						'<tr><th>Landmark </th><th>'+Object.landmark+'</th></tr>'+
						'<tr><th>Phonenumber </th><th>'+Object.phone+'</th></tr>'+
						'<tr><th>Alternative Phonenumber</th><th>'+Object.alterphone+'</th></tr>'+
						'<tr><th>Address</th><th>'+Object.address+'</th></tr>'+
						'<tr><th>Immidiate</th><th>'+immidiate+'</th></tr>'+
						'<tr><th>AvailableTime</th><th>'+Object.availabletime+'</th></tr>'+
					'</table>'+	
				'</div><div class="modal-footer"><button class="btn" data-dismiss="modal" ria-hidden="true">Close</button></div></div>';
				viewAll+='<div id="viewall'+Object.user_medicine_order_id+'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><h3 id="myModalLabel">Prescription</h3></div><div id="popup" class="modal-body">'+
					'<table class="table table-condensed">';
					viewAll+='<tr><th>Tabletname</th>'+
							'<th>Quantity</th></tr>';
					if(details.length>0){
						for(var i=0;i<=(details.length-1);i++){
							var names=details[i].split('$$');
							viewAll+='<tr><th>'+names[0]+'</th>'+
							'<th>'+names[1]+'</th></tr>';
						}
					}
					viewAll+='</table>'+	
				'</div><div class="modal-footer"><button class="btn" data-dismiss="modal" ria-hidden="true">Close</button></div></div>';
				viewallImages+='<div id="image'+Object.user_medicine_order_id+'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><h3 id="myModalLabel">Images</h3></div><div id="popup" class="modal-body">';
				viewallImages+='<div id="myCarousel'+Object.user_medicine_order_id+'" class="carousel slide">'+
				'<ol class="carousel-indicators">';
				if(images.length>0){
					for(var img=0;img<=(images.length)-1;img++){
						//if(img==0){
							viewallImages+='<li data-target="#myCarousel'+Object.user_medicine_order_id+'" data-slide-to="'+img+'" class="active"></li>';
						//}
					}
				}
				viewallImages+='</ol>'+
				'<!-- Carousel items -->'+
				'<div class="carousel-inner">';
				if(images.length>0){
					for(var img=0;img<=(images.length)-1;img++){
						if(img==0){
							viewallImages+='<div class="active item"><img width="500px;" height="500px;" src="'+uploadImgUrl+images[img]+'"></div>';
						}else{
							viewallImages+='<div class="item"><img width="500px;" height="500px;" src="'+uploadImgUrl+images[img]+'"></div>';
						}
						
					}
				}
				viewallImages+='</div>'+
				'<!-- Carousel nav -->'+
				'<a class="carousel-control left" href="#myCarousel'+Object.user_medicine_order_id+'" data-slide="prev">&lsaquo;</a>'+
				'<a class="carousel-control right" href="#myCarousel'+Object.user_medicine_order_id+'" data-slide="next">&rsaquo;</a>'+
				'</div>';
				viewallImages+='</div><div class="modal-footer"><button class="btn" data-dismiss="modal" ria-hidden="true">Close</button></div></div>';
				html+=	'<tr>'+
						'<td>'+Object.date_added+'</td>'+
						'<td>'+phtml+'</td>'+
						'<td>'+imagees+'</td>'+
						'<td id="status'+Object.user_medicine_order_id+'">'+status+'</td>'+
						'<td>'+action+'</td>'+
					'</tr>';
			phtml="";
			imagees="";
		}
			pagei++;
		}
		});
		html+='</table>';
		$('#orderHistory').html(html);
		$('#viewDetailes_id').html(viewDetailes);				
		$('#viewall_detailes').html(viewAll);				
		$('#viewall_Imags').html(viewallImages);
		var status = getParameterByName('status');
		if(status=='cancelled'){
			$('#success_alert').show();
			$("#cancelled_order").html("Cancelled order successfully");
			$("html, body").animate({ scrollTop: 0 }, 600);
			$('#success_alert').delay(3000).fadeOut('slow');
		}
		return false;	
}

function pageselectCallbackShopDiscount(page_index, jq){
	var items_per_page = $('#items_per_page').val();
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var pagei=page_index*items_per_page;
	var count=0;
	var dhtml="";
	var address="";
	var admin_status="";
	
		dhtml+='<table class="table table-bordered">'+
						'<tr class="table_th_bg">'+
						'<th>Post Order Date</th>'+
						'<th>Delivered Date</th>'+
						'<th>Tracking ID</th>'+
						'<th>Admin Status</th>'+
						//'<th>Price</th>'+
						'<th>Discount</th>'+
					'</tr>';
	var obj = eval(members);
	$.each(obj, function (index,Object){
	if(pagei==index){
		if(pagei<max_elem){
			if(Object.admin_paid_status==0){
				admin_status= "Notpaid";
			}else{
				admin_status="Paid";
			}
			count++;
			dhtml+=	'<tr>'+
					'<td>'+Object.added_date+'</td>'+
					'<td>'+Object.delivered_date+'</td>'+
					'<td>'+Object.user_medicine_order_id+'</td>'+
					'<td>'+admin_status+'</td>'+
					'<td>Rs '+Object.discount+'.00</td>'+
				'</tr>';
			address="";
		}
		pagei++;
	}
	});
	dhtml+='</table>';
	$('#discounts').html(dhtml);
	return false;
}			
function pageselectCallbackShopComplaints(page_index, jq){
	var shop_name = JSON.parse(sessionStorage["shop_name"]);
	var items_per_page = $('#items_per_page').val();
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var pagei=page_index*items_per_page;
	var chtml='';
	var obj = eval(members);
	$.each(obj, function (index,Object){
	if(pagei==index){
	if(pagei<max_elem){
		chtml+='<div class="media">'+
				'<a class="pull-left" href="#">'+
					'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
				'</a>'+
				'<div class="media-body">'+
					'<h4 id="shop_name_complaint" class="media-heading">'+Object.user_name+'&nbsp;&nbsp;&nbsp;&nbsp;'+'TRACKING ID:'+Object.complaint_on_id+'</h4>'+
					'<p id="shop_name_complaint_text">'+Object.complaint+'</p>';
		if(Object.reply_text!=null){
			chtml+='<div class="media">'+
				'<a class="pull-left" href="#">'+
				'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
				'</a>'+
				'<div class="media-body">'+
					'<h4 class="media-heading">Replay&nbsp;&nbsp;&nbsp; TRACKING ID:'+Object.user_medicine_order_id+'</h4>'+
					'<p>'+Object.reply_text+'</p>';
				chtml+='</div>'+
			'</div>';
		}else{
			chtml+='<p id="replayP'+Object.complaint_id+'"><a href="javascript:void(0);" class="replay_btn" onclick="replay('+Object.complaint_id+')">Replay</a></p>'+
			'<div  class="media replay_comment_show" id="replay_comment'+Object.complaint_id+'" style="display:none;">'+
				'<a class="pull-left" href="#">'+
					'<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile">'+
				'</a>'+
				'<div class="media-body">'+
					'<textarea id="replaytext'+Object.shop_id+'" class="span10" placeholder="Add a Replay"></textarea>'+
					'<p>Replay by '+shop_name+'&nbsp;&nbsp;<a href="javascript:void(0);" class="submit_comment" onclick="submitReplay('+Object.shop_id+','+Object.complaint_id+','+Object.complaint_on_id+')">Submit Comment</a></p>'+
				'</div><span style="color:red" id="errortext'+Object.shop_id+'"></span>'+
			'</div>'+
			'<div id="appendDivs'+Object.shop_id+'"></div>';
				
		}
	}
	chtml+='</div>'+'</div>';
	pagei++;
	}
	});
	$("#complaint_replies").html(chtml);
	return false;
}		
function pageselectCallbackShopReview(page_index, jq){
	var items_per_page = $('#items_per_page').val();
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var pagei=page_index*items_per_page;
	var html="";
	var rhtml="";
	var obj = eval(members);
	$.each(obj, function (index,Object){
	if(pagei==index){
		if(pagei<max_elem){
			html+='<div class="media">';
			html+='<a class="pull-left" href="#">';
			html+='<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile"></a>';		  
			html+='<div class="media-body">';
			var value=Object.rating;
			for(var i=1;i<=value;i++){
				rhtml+='<img class="star" src="images/green-star.png">';
			}for(var j=i;j<=5;j++){
				rhtml+='<img class="star" src="images/gray-star.png">';
			}
			html+='<h4>'+rhtml+'</h4>';
			html+='<h4 class="media-heading">'+Object.user_name+' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tracking ID: '+Object.tracking_id+'</h4>';
			html+= '<p>'+ Object.review + '</p>';	 	 
			html+='</div>'; 
			html+='</div>';
			rhtml="";
		}
		pagei++;
	}
	});
	$("#all_review_list").html(html);
	return false;
}
function pageselectCallbackShopReview(page_index, jq){
	var items_per_page = $('#items_per_page').val();
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var pagei=page_index*items_per_page;
	var html="";
	var rhtml="";
	var obj = eval(members);
	$.each(obj, function (index,Object){
	if(pagei==index){
		if(pagei<max_elem){
			html+='<div class="media">';
			html+='<a class="pull-left" href="#">';
			html+='<img src="https://lh3.googleusercontent.com/uFp_tsTJboUY7kue5XAsGA=w48-c-h48" class="media-object img_profile"></a>';		  
			html+='<div class="media-body">';
			var value=Object.rating;
			for(var i=1;i<=value;i++){
				rhtml+='<img class="star" src="images/green-star.png">';
			}for(var j=i;j<=5;j++){
				rhtml+='<img class="star" src="images/gray-star.png">';
			}
			html+='<h4>'+rhtml+'</h4>';
			html+='<h4 class="media-heading">'+Object.user_name+' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tracking ID: '+Object.tracking_id+'</h4>';
			html+= '<p>'+ Object.review + '</p>';	 	 
			html+='</div>'; 
			html+='</div>';
			rhtml="";
		}
		pagei++;
	}	
	});
	$("#all_review_list").html(html);
	return false;
}

// Shop Notifications

function shopNotifications(type){
	var shop_id = JSON.parse(sessionStorage["shop_user_id"]);
	$.ajax({
		type		:	'GET',
		url			:  	webServiceUrl+'notifications/'+type+'-'+shop_id,
		dataType	: 	"json",
		success: function(data){
			if(data.value==1){
				var notifications="";
				var notification_type="";
				var action="";
				notifications+='<table class="table table-bordered">'+
				'<tr class="table_th_bg">'+
				'<th>Date</th>'+
				'<th>Notification</th>'+
				'<th>Type</th>'+
				'<th>Action</th>'+
				'</tr>';
				var obj = eval("(" + data.notifications + ")");
				var deletIds="";
				$.each(obj, function (index,Object){
					if(Object.type=="Complaint"){
						notification_type=Object.type +' By Your Order Tracking Id '+Object.order_id ;
						action='<a href="javascript:void(0)" onclick="viewComplaintNotifications('+Object.notifications_id+',5,'+Object.user_type_id+')">VIEW</a>';
					}else if(Object.type=="ReviewRating"){
						notification_type='Post A '+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
						action='<a href="javascript:void(0)" onclick="viewReviwNotifications('+Object.notifications_id+',6,'+Object.user_type_id+')">VIEW</a>';
					}else if(Object.type=="sendQuotation"){
						notification_type='Admin '+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
						action='<a href="javascript:void(0)" onclick="viewSendQuotationNotifications('+Object.shop_id+',10,'+Object.user_type_id+')">VIEW</a>';
					}else if(Object.type=="Confirmed"){
						/*if(Object.status==1){
							notification_type='Admin Not Confirmaed By Order Tracking Id '+Object.order_id ;
							action='<a href="javascript:void(0)" onclick="viewConfirmedNotifications('+Object.shop_id+',12,'+Object.user_type_id+')">VIEW</a>';
						}else if(Object.status==3){
							notification_type='Admin Not Confirmaed By Order Tracking Id '+Object.order_id ;
							action='<a href="javascript:void(0)" onclick="viewConfirmedNotifications('+Object.shop_id+',12,'+Object.user_type_id+')">VIEW</a>';
						}else{*/
						if(Object.status==2){
							notification_type='Admin Confirmaed By Order Tracking Id '+Object.order_id ;
							action='<a href="javascript:void(0)" onclick="viewConfirmedNotifications('+Object.shop_id+',12,'+Object.user_type_id+')">VIEW</a>';
						}
					}else if(Object.type=="Discount"){
						notification_type='Admin Recived'+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
						action='<a href="javascript:void(0)" onclick="viewDiscountNotifications('+Object.notifications_id+',13,'+Object.user_type_id+')">VIEW</a>';
					}else if(Object.type=="Block"){
						notification_type='Admin '+ Object.type +'Your Account ';
						action='<a href="javascript:void(0)" >VIEW</a>';
					}else if(Object.type=="Active"){
						notification_type='Admin '+ Object.type +'Your Account ';
						action='<a href="javascript:void(0)" >VIEW</a>';
					}
					notifications+=	'<tr>'+
						'<td>'+Object.added_date+'</td>'+
						'<td>'+notification_type+'</td>'+
						'<td>'+Object.type+'</td>'+
						'<td>'+action+'</td>'+
					'</tr>';
				});
				$('#notifications').html(notifications);
				$('#count').html("");
			}else{
				$('#notifications').html("Notifications Empty");
			}
		}
	});
}
function viewComplaintNotifications(orderId,orderType,usertype ){
	changeNotificationStatus(orderId,1,orderType,usertype,3 );
}
function viewReviwNotifications(orderId,orderType,usertype ){
	changeNotificationStatus(orderId,2,orderType,usertype,3 );
}
function viewSendQuotationNotifications(orderId,orderType,usertype){
	changeNotificationStatus(orderId,3,orderType,usertype,2 );
}
function viewConfirmedNotifications(orderId,orderType,usertype){
	changeNotificationStatus(orderId,4,orderType,usertype,2 );
}
function viewDiscountNotifications(orderId,orderType,usertype){
	changeNotificationStatus(orderId,5,orderType,usertype,3 );
}
function changeNotificationStatus(orderId,type,orderType,usertype,updatetype){
	$.ajax({
		type		:	'PUT',
		url			:  	webServiceUrl+'notifications/'+orderId,
		dataType	: 	"json",
		data		:	{
							OrderType:orderType,userType:usertype,updatetype:updatetype
						},
		success: function(data){
			if(data.value==1){
				if(type==1){
					window.location="complaints.html";
				}else if(type==2){
					window.location="reviews.html";
				}else if(type==3){
					window.location="order-history.html";
				}else if(type==4){
					window.location="order-history.html";
				}else if(type==5){
					window.location="discounts.html";
				}
			}
		}
	});	
}
function getAllShopNotifications(type){
var shop_id = JSON.parse(sessionStorage["shop_user_id"]);
	$.ajax({
		type		:	'POST',
		url			:  	webServiceUrl+'notifications',
		dataType	: 	"json",
		data		:	{usertype:type,user_id:shop_id},
		success: function(data){
			if(data.value==1){
				var adminnotifications="";
				var adminnotification_type="";
				adminnotifications+='<table class="table table-bordered">'+
				'<tr class="table_th_bg">'+
				'<th>Date</th>'+
				'<th>Notification</th>'+
				'<th>Type</th>'+
				'</tr>';
				var obj = eval("(" + data.noitifications + ")");
				var deletIds="";
				$.each(obj, function (index,Object){
					if(Object.type=="Complaint"){
						adminnotification_type=Object.type +' By Your Order Tracking Id '+Object.order_id ;
					}else if(Object.type=="ReviewRating"){
						adminnotification_type='Post A '+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
					}else if(Object.type=="sendQuotation"){
						adminnotification_type='Admin '+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
					}else if(Object.type=="Confirmed"){
						if(Object.status==1){
							adminnotification_type='Admin'+ Object.type +' By Order Tracking Id '+Object.order_id ;
						}else if(Object.status==3){
							adminnotification_type='Admin Not Confirmaed By Order Tracking Id '+Object.order_id ;
						}else{
							adminnotification_type='Admin Confirmaed By Order Tracking Id '+Object.order_id ;
						}
					}else if(Object.type=="Discount"){
						adminnotification_type='Admin Recived'+ Object.type +' By Your Order Tracking Id '+Object.order_id ;
					}else if(Object.type=="Block"){
						adminnotification_type='Admin '+ Object.type +'Your Account ';
					}else if(Object.type=="Active"){
						adminnotification_type='Admin '+ Object.type +'Your Account ';
					}
					adminnotifications+='<tr>'+
						'<td>'+Object.added_date+'</td>'+
						'<td>'+adminnotification_type+'</td>'+
						'<td>'+Object.type+'</td>'+
					'</tr>';
				});
				$('#notifications').html(adminnotifications);
			}else{
				$('#notifications').html("History Is Empty");
			}
		}
	});	
}